//
//  JSLLoginController.m
//  JingleSpeedLoan
//
//  Created by 宋质彬 on 2018/7/6.
//  Copyright © 2018年 宋质彬. All rights reserved.
//

#import "JSLLoginController.h"
#import "JSLHelpCenteryController.h"

@interface JSLLoginController ()<UITextFieldDelegate>
@property (nonatomic, strong) UITextField   *tfTele;
@property (nonatomic, strong) UITextField   *tfPwd;

@property (nonatomic , weak) UIButton *passwordLoginButton;
@property (nonatomic , weak) UIButton *verificationCodeLoginButton;
@property (nonatomic , weak) UILabel *iponeTextLable;
@property (nonatomic , weak) UITextField *iponeTextField;
@property (nonatomic , weak) UIView *iphonelineView;
@property (nonatomic , weak) UILabel *passwordTextLab;
@property (nonatomic , weak) UILabel *passwordTextRightLab;
@property (nonatomic , weak) UITextField *passwordField;
@property (nonatomic , weak) UIView *passwordlineView;
@property (nonatomic , weak) UIButton *loginButton;
@property (nonatomic , weak) UIButton *rigestButton;
@property (nonatomic , weak) UILabel *tiemCountLab;
@property (nonatomic , weak) UIView *loginBottomLeftView;
@property (nonatomic , weak) UIView *loginBottomRightView;
@property (nonatomic , weak) UIButton *forgetPasswordButton;
@property (nonatomic , weak) UILabel *warnlabel;


@property (nonatomic , weak) UILabel *verificationCodeTextlabel;
@property (nonatomic , weak) UIButton *getVerificationCodeButto;

@property (nonatomic , strong) NSTimer *timer;
@property (nonatomic, assign) int                   second;
@property (nonatomic , assign) BOOL isPasswordLogin;

@property (nonatomic , weak) UIButton *gouButton;
@property (nonatomic , assign) BOOL isSelectState;

@end

@implementation JSLLoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    [self setUpView];
    
      [self setUpViews];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)yanZhengIphoneIsRegist{
}
#pragma mark - 点击事件
- (void)buttonClick:(UIButton *)sender{
    
    [self.iponeTextField resignFirstResponder ];
    [self.passwordField resignFirstResponder ];
    
    switch (sender.tag) {
        case 10:// 密码登录
        {
            [self.passwordLoginButton setTitleColor:THEME_COLOR forState:UIControlStateNormal];
            [self.verificationCodeLoginButton setTitleColor:[@"#999999" hexStringToColor] forState:UIControlStateNormal];
            self.loginBottomLeftView.hidden = NO;
            self.loginBottomRightView.hidden = YES;
            
            self.forgetPasswordButton.hidden = NO;
            self.getVerificationCodeButto.hidden = YES;
            self.isPasswordLogin = YES;
            self.passwordField.secureTextEntry = YES;
            self.passwordField.placeholder =@"请输入密码";
            self.passwordField.text = nil;
            [self textFieldChange:nil];
        }
            break;
            
        case 11:// 验证码登录
        {
            [self.passwordLoginButton setTitleColor:[@"#646a75" hexStringToColor] forState:UIControlStateNormal];
            [self.verificationCodeLoginButton setTitleColor:[@"#2f7cff" hexStringToColor] forState:UIControlStateNormal];
            self.loginBottomLeftView.hidden = YES;
            self.loginBottomRightView.hidden = NO;
            
            self.forgetPasswordButton.hidden = YES;
            self.getVerificationCodeButto.hidden = NO;
            self.passwordField.text = nil;
            self.isPasswordLogin = NO;
            self.passwordField.placeholder =@"请输入验证码";
            self.passwordField.secureTextEntry = NO;
            
            [self textFieldChange:nil];
            
        }
            break;
            
        case 12:// 登录
        {
            if (self.isPasswordLogin) {// 密码登录
                
              
                
            }else{// 验证码登录
                
               
                
            }
            
        }
            break;
            
        case 13:// 注册
        {
            JSLHelpCenteryController *vc = [[JSLHelpCenteryController alloc] init];
            vc.fileName = @"protocol.html";
            vc.title = @"服务协议";
            [self pushViewController:vc animated:YES];
        }
            break;
            
        case 14:// 忘记密码
        {
     
        }
            break;
            
        case 15:// 获取验证码
        {
          
        }
            break;
            
        case 16:
        {
            
        }
            break;
            
        default:
            break;
    }
}

- (void)textFieldChange:(UITextField *)sender{
    
    if (self.isPasswordLogin) {
        if ([self.iponeTextField.text trimmingWhitespaceAndNewlines].length == 11 && !([self.passwordField.text trimmingWhitespaceAndNewlines].length < 6)) {
            
            self.loginButton.layer.cornerRadius = 4;
            self.loginButton.layer.masksToBounds = YES;
            self.loginButton.backgroundColor = THEME_COLOR;
            [self.loginButton setTitleColor:[@"#ffffff" hexStringToColor] forState:UIControlStateNormal];
            
            self.loginButton.enabled = YES;
        }else{
            self.loginButton.layer.cornerRadius = 4;
            self.loginButton.layer.masksToBounds = YES;
            [self.loginButton setTitleColor:[@"#a9aabc" hexStringToColor] forState:UIControlStateNormal];
            self.loginButton.backgroundColor = RGBACOLOR(169, 170, 188, 0.2);;
            self.loginButton.enabled = NO;
        }
        
    }else{
        if ([self.iponeTextField.text trimmingWhitespaceAndNewlines].length == 11 && !([self.passwordField.text isEmptyOrWhitespace])) {
            
            
            
     
            self.loginButton.layer.cornerRadius = 4;
            self.loginButton.layer.masksToBounds = YES;
            self.loginButton.backgroundColor = THEME_COLOR;
            [self.loginButton setTitleColor:[@"#ffffff" hexStringToColor] forState:UIControlStateNormal];
            
            self.loginButton.enabled = YES;
        }else{
    
            self.loginButton.layer.cornerRadius = 4;
            self.loginButton.layer.masksToBounds = YES;
            [self.loginButton setTitleColor:[@"#a9aabc" hexStringToColor] forState:UIControlStateNormal];
            self.loginButton.backgroundColor = RGBACOLOR(169, 170, 188, 0.2);;
            self.loginButton.enabled = NO;
        }
        
    }
    
}

- (void)setUpView{
    self.navigationItem.title = @"登录";
    [self baseConfig:PageGobackTypeDismiss];
    
    //创建视图等
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.passwordLoginButton= [JSLKitFactory jsl_titleButtonWithFrame:CGRectZero superView:self.view font:LIGHT_FONT(14) titleColor:[@"#2BA6FF" hexStringToColor] backgroundColor:nil title:@"密码登录" target:self action:@selector(buttonClick:)];
    self.passwordLoginButton.tag = 10;
    self.passwordLoginButton.frame = CGRectMake(0, 30*AutoSizeScaleYY, self.view.width *0.5, 40*AutoSizeScaleYY);
    
    self.verificationCodeLoginButton= [JSLKitFactory jsl_titleButtonWithFrame:CGRectZero superView:self.view font:LIGHT_FONT(14) titleColor:[@"#999999" hexStringToColor] backgroundColor:[UIColor whiteColor] title:@"验证码登录" target:self action:@selector(buttonClick:)];
    self.verificationCodeLoginButton.tag = 11;
    self.verificationCodeLoginButton.frame = CGRectMake(self.passwordLoginButton.right, self.passwordLoginButton.top, self.passwordLoginButton.width, self.passwordLoginButton.height);
    

    self.loginBottomLeftView = [JSLKitFactory jsl_viewWithFrame:CGRectZero backgroundColor:THEME_COLOR superView:self.passwordLoginButton];
    self.loginBottomLeftView.hidden = NO;
    self.loginBottomLeftView.frame = CGRectMake(self.passwordLoginButton.width*0.5-45, self.passwordLoginButton.height -3, 90, 3);


    self.loginBottomRightView = [JSLKitFactory jsl_viewWithFrame:CGRectZero backgroundColor:THEME_COLOR superView:self.verificationCodeLoginButton];;
    self.loginBottomRightView.hidden = YES;
    self.loginBottomRightView.frame = CGRectMake(self.verificationCodeLoginButton.width*0.5-45, self.verificationCodeLoginButton.height -3, 90, 3);

    

    UITextField *iphone = [[UITextField alloc] init];
    iphone.tag = 1000 ;
    iphone.delegate = self;
    [iphone addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    iphone.placeholder = @"请输入手机号";
    iphone.textColor = [@"#D0D0D0" hexStringToColor];
    iphone.font = LIGHT_FONT(15);
    iphone.clearButtonMode =  UITextFieldViewModeWhileEditing;
    iphone.keyboardType = UIKeyboardTypeNumberPad;
    iphone.backgroundColor = self.view.backgroundColor;
    iphone.secureTextEntry = NO;
    [self.view addSubview:iphone];
    self.iponeTextField = iphone;
    
    iphone.frame = CGRectMake(31*AutoSizeScaleXX, self.passwordLoginButton.bottom +44*AutoSizeScaleYY, SCREEN_WIDTH -31*AutoSizeScaleXX*2, 40*AutoSizeScaleYY);
    
    
    UITextField *password = [[UITextField alloc] init];
    password.tag = 1001 ;
    password.delegate = self;
    [password addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    password.placeholder = @"请输入密码";
    password.textColor = [@"#D0D0D0" hexStringToColor];
    password.font = LIGHT_FONT(15);
    password.clearButtonMode =  UITextFieldViewModeWhileEditing;
    password.keyboardType = UIKeyboardTypeDefault;
    password.backgroundColor = self.view.backgroundColor;
    password.secureTextEntry = YES;
    [self.view addSubview:password];
    self.passwordField = password;
    
    password.frame = CGRectMake(31*AutoSizeScaleXX, self.iponeTextField.bottom +20*AutoSizeScaleYY, SCREEN_WIDTH -31*AutoSizeScaleXX*2, 40*AutoSizeScaleYY);
    
    self.iphonelineView = [JSLKitFactory jsl_viewWithFrame:CGRectZero backgroundColor:[@"#d8d8d8" hexStringToColor] superView:self.view];
    self.iphonelineView.frame = CGRectMake(self.iponeTextField.left, self.iponeTextField.bottom, self.iponeTextField.width, 1);
    
    
    self.passwordlineView = [JSLKitFactory jsl_viewWithFrame:CGRectZero backgroundColor:[@"#d8d8d8" hexStringToColor] superView:self.view];;
     self.passwordlineView.frame = CGRectMake(self.passwordField.left, self.passwordField.bottom, self.passwordField.width, 1);
    
    
    
    self.forgetPasswordButton = [JSLKitFactory jsl_titleButtonWithFrame:CGRectZero superView:self.view font:LIGHT_FONT(12) titleColor:THEME_COLOR backgroundColor:self.view.backgroundColor title:@"忘记密码" target:self action:@selector(buttonClick:)];;
    self.forgetPasswordButton.tag = 14;
    CGSize size = [@"忘记密码" sizeWithAttributes:@{NSFontAttributeName :self.forgetPasswordButton.titleLabel.font}];
    self.forgetPasswordButton.frame = CGRectMake(self.view.width-31*AutoSizeScaleXX-size.width, self.iphonelineView.bottom +33*AutoSizeScaleYY, size.width, size.height);
   

    self.warnlabel = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:@"我只错误" font:LIGHT_FONT(14) textColor:[@"ff413d" hexStringToColor] textAlignment:NSTextAlignmentCenter SuperView:self.view];
    self.warnlabel.frame = CGRectMake(0, self.passwordlineView.bottom +15*AutoSizeScaleYY, self.view.width, 20*AutoSizeScaleYY);
    
    self.loginButton = [JSLKitFactory jsl_titleButtonWithFrame:CGRectZero superView:self.view font:LIGHT_FONT(17) titleColor:[@"#a9aabc" hexStringToColor] backgroundColor:RGBACOLOR(169,170,188,0.2) title:@"登录" target:self action:@selector(buttonClick:)];
    self.loginButton.layer.cornerRadius = 4;
    self.loginButton.layer.masksToBounds = YES;
    self.loginButton.tag = 12;
    self.loginButton.enabled = NO;

    self.loginButton.frame = CGRectMake(29*AutoSizeScaleXX, self.passwordlineView.bottom +60*AutoSizeScaleYY, self.view.width -29*AutoSizeScaleXX*2, 42*AutoSizeScaleXX);
  
    
    UILabel *label = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:@"没有帐号?" font:LIGHT_FONT(13) textColor:[@"#999999" hexStringToColor] textAlignment:NSTextAlignmentLeft SuperView:self.view];
    CGSize scrsize = [label.text sizeWithAttributes:@{NSFontAttributeName :label.font}];
    label.frame = CGRectMake(self.view.width*0.5 -scrsize.width, self.loginButton.bottom + 14*AutoSizeScaleYY, scrsize.width, scrsize.height);
    
    self.rigestButton = [JSLKitFactory jsl_titleButtonWithFrame:CGRectZero superView:self.view font:LIGHT_FONT(13) titleColor:THEME_COLOR backgroundColor:self.view.backgroundColor title:@"立即注册" target:self action:@selector(buttonClick:)];
    self.rigestButton.tag = 13;
    CGSize jjSize = [@"立即注册" sizeWithAttributes:@{NSFontAttributeName : LIGHT_FONT(13)}];
    self.rigestButton.frame = CGRectMake(label.right, label.top, jjSize.width, jjSize.height);
    
    

    self.getVerificationCodeButto = [JSLKitFactory jsl_titleButtonWithFrame:CGRectZero superView:self.view font:LIGHT_FONT(12) titleColor:THEME_COLOR backgroundColor:self.view.backgroundColor title:@"获取验证码" target:self action:@selector(buttonClick:)];
    self.getVerificationCodeButto.hidden =YES;
    self.getVerificationCodeButto.tag = 15;
    
    CGSize verSize = [@"获取验证码" sizeWithAttributes:@{NSFontAttributeName :self.forgetPasswordButton.titleLabel.font}];
    self.getVerificationCodeButto.frame = CGRectMake(self.view.width-31*AutoSizeScaleXX-verSize.width, self.iphonelineView.bottom +33*AutoSizeScaleYY, verSize.width, verSize.height);

    [self configViewMonaryFrame];
    
}


- (void)setUpViews{
    self.navigationItem.title = @"登录";
    [self baseConfig:PageGobackTypeDismiss];
    
    UITextField *iphone = [[UITextField alloc] init];
    iphone.tag = 1000 ;
    iphone.delegate = self;
    [iphone addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    iphone.placeholder = @"请输入手机号";
    iphone.textColor = [@"#333333" hexStringToColor];
    iphone.font = LIGHT_FONT(15);
    iphone.clearButtonMode =  UITextFieldViewModeWhileEditing;
    iphone.keyboardType = UIKeyboardTypeNumberPad;
    iphone.backgroundColor = self.view.backgroundColor;
    iphone.secureTextEntry = NO;
    [self.view addSubview:iphone];
    self.iponeTextField = iphone;
    
    iphone.frame = CGRectMake(31*AutoSizeScaleXX, 97*AutoSizeScaleYY, SCREEN_WIDTH -31*AutoSizeScaleXX*2, 40*AutoSizeScaleYY);
    
    
    UITextField *password = [[UITextField alloc] init];
    password.tag = 1001 ;
    password.delegate = self;
    [password addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    password.placeholder = @"请输入验证码";
    password.textColor = [@"#333333" hexStringToColor];
    password.font = LIGHT_FONT(15);
    password.clearButtonMode =  UITextFieldViewModeWhileEditing;
    password.keyboardType = UIKeyboardTypeDefault;
    password.backgroundColor = self.view.backgroundColor;
    password.secureTextEntry = NO;
    [self.view addSubview:password];
    self.passwordField = password;
    
    password.frame = CGRectMake(31*AutoSizeScaleXX, self.iponeTextField.bottom +20*AutoSizeScaleYY, SCREEN_WIDTH -31*AutoSizeScaleXX*2, 40*AutoSizeScaleYY);
    
    self.iphonelineView = [JSLKitFactory jsl_viewWithFrame:CGRectZero backgroundColor:[@"#d8d8d8" hexStringToColor] superView:self.view];
    self.iphonelineView.frame = CGRectMake(self.iponeTextField.left, self.iponeTextField.bottom, self.iponeTextField.width, 1);
    
    
    self.passwordlineView = [JSLKitFactory jsl_viewWithFrame:CGRectZero backgroundColor:[@"#d8d8d8" hexStringToColor] superView:self.view];;
    self.passwordlineView.frame = CGRectMake(self.passwordField.left, self.passwordField.bottom, self.passwordField.width, 1);
    
    
    self.getVerificationCodeButto = [JSLKitFactory jsl_titleButtonWithFrame:CGRectZero superView:self.view font:LIGHT_FONT(12) titleColor:THEME_COLOR backgroundColor:self.view.backgroundColor title:@"获取验证码" target:self action:@selector(verButtonClick:)];
    self.getVerificationCodeButto.hidden =NO;
    self.getVerificationCodeButto.tag = 15;
    
    CGSize verSize = [@"获取验证码" sizeWithAttributes:@{NSFontAttributeName :self.getVerificationCodeButto.titleLabel.font}];
    self.getVerificationCodeButto.frame = CGRectMake(self.view.width-31*AutoSizeScaleXX-verSize.width, 97*AutoSizeScaleYY+10*AutoSizeScaleYY, verSize.width, verSize.height);
    
    
    self.warnlabel = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:@"" font:LIGHT_FONT(12) textColor:[@"ff413d" hexStringToColor] textAlignment:NSTextAlignmentCenter SuperView:self.view];
    self.warnlabel.frame = CGRectMake(0, self.passwordlineView.bottom +10*AutoSizeScaleYY, self.view.width, 20*AutoSizeScaleYY);
    
    self.loginButton = [JSLKitFactory jsl_titleButtonWithFrame:CGRectZero superView:self.view font:LIGHT_FONT(17) titleColor:[@"#a9aabc" hexStringToColor] backgroundColor:RGBACOLOR(169,170,188,0.2) title:@"登录" target:self action:@selector(loginButtonClick:)];
    self.loginButton.layer.cornerRadius = 4;
    self.loginButton.layer.masksToBounds = YES;
    self.loginButton.tag = 12;
    self.loginButton.enabled = NO;
    
    self.loginButton.frame = CGRectMake(29*AutoSizeScaleXX, self.passwordlineView.bottom +70*AutoSizeScaleYY, self.view.width -29*AutoSizeScaleXX*2, 42*AutoSizeScaleXX);
    
    
    UILabel *label = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:@"我已经阅读并同意?" font:LIGHT_FONT(10) textColor:[@"#999999" hexStringToColor] textAlignment:NSTextAlignmentLeft SuperView:self.view];
    CGSize scrsize = [label.text sizeWithAttributes:@{NSFontAttributeName :label.font}];
    
    self.gouButton = [JSLKitFactory jsl_imageButtonWithFrame:CGRectZero superView:self.view setImage:@"gou-sel" setBackImage:nil target:self action:@selector(gouImageButton:)];
//    self.gouButton.backgroundColor = [UIColor redColor];
    
    self.gouButton.frame = CGRectMake(self.loginButton.left, self.loginButton.top -10*AutoSizeScaleYY -12*AutoSizeScaleXX, 12*AutoSizeScaleXX, 12*AutoSizeScaleXX);
    
    
    label.frame = CGRectMake(self.gouButton.right +5*AutoSizeScaleXX, self.loginButton.top -10*AutoSizeScaleYY - scrsize.height, scrsize.width, scrsize.height);
    
    self.rigestButton = [JSLKitFactory jsl_titleButtonWithFrame:CGRectZero superView:self.view font:LIGHT_FONT(10) titleColor:THEME_COLOR backgroundColor:self.view.backgroundColor title:@"《叮当账单用户服务协议》" target:self action:@selector(buttonClick:)];
    self.rigestButton.tag = 13;
    CGSize jjSize = [@"《叮当账单用户服务协议》" sizeWithAttributes:@{NSFontAttributeName : LIGHT_FONT(10)}];
    self.rigestButton.frame = CGRectMake(label.right, label.top, jjSize.width, jjSize.height);
    
    
}

- (void)gouImageButton:(UIButton *)button{
    self.isSelectState = !self.isSelectState;
    if (self.isSelectState) {
        [button setImage:[UIImage imageNamed:@"gou-select"] forState:UIControlStateNormal];
    }else {
        [button setImage:[UIImage imageNamed:@"gou-sel"] forState:UIControlStateNormal];
    }
}
- (void)verButtonClick:(UIButton *)button{
    
    [self keyBoardDiss];
    
    if ([JSLKitFactory isNotNull:self.iponeTextField.text]) {
        [self getSmsCode];
    }else{
        NSLog(@"手机号不能为空");
        [self showMessage:@"手机号不能为空"];
    }
    
    
    
   
}
- (void)keyBoardDiss{
    [self.iponeTextField resignFirstResponder];
    [self.passwordField resignFirstResponder];
}
- (void)getSmsCode {
    [self beginTimer];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
    parameters[@"userPhone"] = self.iponeTextField.text;
    [HttpRequest POST:LOGIN_VERFCODE_URL parameters:parameters success:^(id  _Nullable result, NSString * _Nullable successMessage) {
        NSLog(@"%@",result);
        [self showMessage:@"验证码获取成功"];
        
        
    } failure:^(NSInteger code, NSString * _Nullable errorMessage) {
        
        [self showMessage:errorMessage];
    }];
    
}

- (void)loginButtonClick:(UIButton *)button{
    
    
    [self keyBoardDiss];
    if (self.isSelectState) {
        if ([JSLKitFactory isNotNull:self.iponeTextField.text] && [JSLKitFactory isNotNull:self.passwordField.text]) {
            
            [self getLoginAction];
            
        }else {
            [self showLoading:@"请输入完整信息"];
        }
        
    }else {
        self.warnlabel.text = @"请勾选我已经阅读并同意？《叮当账单用户服务协议》";
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.warnlabel.text = nil;
            
        });
    }
    
    
    
    
}

- (void)getLoginAction {
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
    parameters[@"userPhone"] = self.iponeTextField.text;
    parameters[@"code"] = self.passwordField.text;
    [HttpRequest POST:LOGIN_URL parameters:parameters success:^(id  _Nullable result, NSString * _Nullable successMessage) {
        NSLog(@"%@",result);
        
        
        
        // 保存x-access-phone
        [[NSUserDefaults standardUserDefaults] setObject:self.iponeTextField.text forKey:@"token"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        
        // 跳转
        NSLog(@"%@",result);
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
        [self configUserInfo];
        
    } failure:^(NSInteger code, NSString * _Nullable errorMessage) {
        
        [self showMessage:errorMessage];
    }];
}

- (void)configUserInfo{
#pragma mark - 获取用户信息
    
    // 设置token
    NSString *userToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
    parameters[@"userPhone"] = userToken;
    
    [HttpRequest POST:USERINFO_URL parameters:parameters success:^(id  _Nullable result, NSString * _Nullable successMessage) {
        
        NSLog(@"%@",result);
        NSDictionary *userDict = result[@"data"];
        
        // 创建用户模型
        UserInfo *userModel =   [UserInfo yy_modelWithJSON:userDict.yy_modelToJSONString];
        // 创建用户模型管理者
        [UserManager manager].userInfo = userModel;
        
    } failure:^(NSInteger code, NSString * _Nullable errorMessage) {
        // 清空用户模型
        UserInfo *userModel = [UserInfo yy_modelWithJSON:@""];
        [UserManager manager].userInfo = userModel;
        [UserManager  logout];
        NSLog(@"%@",errorMessage);
        
    }];
    
}


#pragma mark - View创建与设置
- (void)configViewMonaryFrame{
    
   
    
}

- (void)protocol_verfAction {
    
}


- (void)beginTimer{
    
    if (_timer) {
        [_timer invalidate];
        _timer = nil;
    }
    
    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(handleTime) userInfo:nil repeats:YES];
    
    _second = 60;
    
}

-(void)handleTime
{
    
    if (_second>=0) {
        [self.getVerificationCodeButto setTitle:[NSString stringWithFormat:@"%lds后重试",(long)_second] forState:UIControlStateNormal];
        self.getVerificationCodeButto.userInteractionEnabled = NO;
        [self.getVerificationCodeButto setTitleColor:[@"#888888" hexStringToColor] forState:UIControlStateNormal];
        self.getVerificationCodeButto.titleLabel.font = REGULAR_FONT(12);
        _second--;
    }else{
        [self.getVerificationCodeButto setTitle:@"重新获取" forState:UIControlStateNormal];
        [self.getVerificationCodeButto setTitleColor:THEME_COLOR forState:UIControlStateNormal];
        self.getVerificationCodeButto.titleLabel.font = REGULAR_FONT(12);
        self.getVerificationCodeButto.userInteractionEnabled = YES;
        
        if (_timer) {
            [_timer invalidate];
            _timer = nil;
        }
    }
}


- (void)dealloc {
    
    if (_timer) {
        [_timer invalidate];
        _timer = nil;
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
